#define LOG_TAG "LCM"

#ifndef BUILD_LK
#include <linux/string.h>
#include <linux/kernel.h>
#endif

#include "lcm_drv.h"

#ifdef BUILD_LK
#include <platform/upmu_common.h>
#include <platform/mt_gpio.h>
#include <platform/mt_i2c.h>
#include <platform/mt_pmic.h>
#include <string.h>
#elif defined(BUILD_UBOOT)
#include <asm/arch/mt_gpio.h>
#else
#include <mach/mt_pm_ldo.h>
#include <mach/mt_gpio.h>
#endif

#ifdef BUILD_LK
#define LCM_LOGI(string, args...)  dprintf(0, "[LK/"LOG_TAG"]"string, ##args)
#define LCM_LOGD(string, args...)  dprintf(1, "[LK/"LOG_TAG"]"string, ##args)
#else
#define LCM_LOGI(fmt, args...)  pr_debug("[KERNEL/"LOG_TAG"]"fmt, ##args)
#define LCM_LOGD(fmt, args...)  pr_debug("[KERNEL/"LOG_TAG"]"fmt, ##args)
#endif

static LCM_UTIL_FUNCS lcm_util;

#define SET_RESET_PIN(v)			(lcm_util.set_reset_pin((v)))
#define MDELAY(n)					(lcm_util.mdelay(n))

/* --------------------------------------------------------------------------- */
/* Local Functions */
/* --------------------------------------------------------------------------- */
#define dsi_set_cmdq_V2(cmd, count, ppara, force_update) \
	lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
#define dsi_set_cmdq(pdata, queue_size, force_update) \
	lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
#define wrtie_cmd(cmd) \
	lcm_util.dsi_write_cmd(cmd)
#define write_regs(addr, pdata, byte_nums) \
	lcm_util.dsi_write_regs(addr, pdata, byte_nums)
#define read_reg(cmd) \
	lcm_util.dsi_dcs_read_lcm_reg(cmd)
#define read_reg_v2(cmd, buffer, buffer_size) \
	lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
#define set_gpio_lcd_enp(cmd) \
		lcm_util.set_gpio_lcd_enp_bias(cmd)
		

static const unsigned char LCD_MODULE_ID = 0x01;
/* --------------------------------------------------------------------------- */
/* Local Constants */
/* --------------------------------------------------------------------------- */
#define LCM_DSI_CMD_MODE	0
#define FRAME_WIDTH  										 (720)
#define FRAME_HEIGHT 										 (1600)

#define REGFLAG_DELAY             							 0xFFFA
#define REGFLAG_UDELAY             							 0xFFFB
#define REGFLAG_PORT_SWAP									 0xFFFC
#define REGFLAG_END_OF_TABLE      							 0xFFFD   // END OF REGISTERS MARKER

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

/* --------------------------------------------------------------------------- */
/* Local Variables */
/* --------------------------------------------------------------------------- */

struct LCM_setting_table
{
    unsigned int cmd;
    unsigned char count;
    unsigned char para_list[64];
};

static struct LCM_setting_table lcm_suspend_setting[] =
{
    {0x28, 1, {0x00}},
    {REGFLAG_DELAY, 10, {}},
    {0x10, 1, {0x00}},
    {REGFLAG_DELAY, 60, {} },
};

static struct LCM_setting_table lcm_initialization_setting[] =
{
//-------------  Display Initial Code Setting  -------------------------
       {0x41,1,{0x5A}},
 

		
	{0x41,2,{0x5A,0x24}},
        {0x90,1,{0x5a}},
 
//VCOM
        {0x41,2,{0x5A,0x03}},
        {0x80,2,{0x25,0x01}},

//----------------------LCD initial code start----------------------//

        {0x41,2,{0x5A,0x08}},
        {0x80,3,{0xc8,0x2c,0x01}},

        {0x41,2,{0x5A,0x09}},
        {0x80,16,{0x5A,0x51,0xB5,0x2A,0x6C,0xE5,0x4A,0x01,0x40,0x62,0x0F,0x82,0x20,0x08,0xF0,0xB7}},
        {0x90,16,{0x00,0x24,0x42,0x0A,0xE3,0x91,0xA4,0xF0,0xAF,0x61,0x69,0x20,0x69,0x81,0x26,0x00}},
        {0xA0,16,{0x51,0x55,0x55,0x00,0xA0,0x4C,0x06,0x11,0x0D,0x60,0x5A,0xFF,0xFF,0x03,0xA5,0xE6}},
        {0xB0,16,{0x08,0xC9,0x16,0x64,0x0B,0x00,0x00,0x11,0x07,0x60,0x00,0xFF,0xFF,0x03,0xFF,0x34}},
        {0xC0,8,{0x0C,0x3F,0x1F,0x9F,0x0F,0x00,0x08,0x00}},

        {0x41,2,{0x5A,0x0A}},
        {0x80,16,{0xFF,0xB6,0x6D,0x03,0x00,0x0E,0x1A,0x2A,0x3B,0x4C,0x52,0x87,0x62,0xA0,0x92,0x59}},
        {0x90,16,{0x86,0x58,0x53,0x43,0x31,0x22,0x14,0x0B,0x00,0x0E,0x1A,0x2A,0x3B,0x4C,0x52,0x87}},
        {0xA0,13,{0x62,0xA0,0x92,0x59,0x86,0x58,0x53,0x43,0x31,0x22,0x14,0x0B,0x00}},

        {0x41,2,{0x5A,0x0B}},
        {0x80,16,{0x00,0x00,0x20,0x44,0x08,0x00,0x60,0x47,0x00,0x00,0x10,0x22,0x04,0x00,0xB0,0x23}},
        {0x90,2,{0x15,0x00}},
//Blank 13
        {0x41,2,{0x5A,0x0C}},
        {0x80,16,{0xFA,0x68,0x68,0x01,0xB2,0x75,0xB0,0x04,0x00,0x60,0x15,0x00,0x50,0x15,0x56,0x51}},
        {0x90,16,{0x15,0x55,0x61,0x15,0x00,0x60,0x15,0x00,0x50,0x15,0x56,0x51,0x15,0x55,0x61,0x95}},
        {0xA0,16,{0xAB,0x18,0x00,0x05,0x00,0x05,0x00,0x05,0x80,0x4C,0x29,0x84,0x52,0x01,0x09,0x00}},
        {0xB0,2,{0x00,0x00}},
//Blank 14
        {0x41,2,{0x5A,0x0D}},
        {0x80,7,{0xF0,0xB1,0x71,0xEF,0x4B,0xC0,0x80}},
//Blank 15
        {0x41,2,{0x5A,0x0E}},
        {0x80,8,{0xFF,0x01,0x55,0x55,0x32,0x88,0x88,0x1C}},
//Blank 16
        {0x41,2,{0x5A,0x0F}},
        {0x80,16,{0x9D,0x44,0x6B,0xC0,0x12,0x20,0xC4,0x08,0x52,0x51,0x58,0x49,0x03,0x52,0x4C,0x4C}},
        {0x90,16,{0x68,0x68,0x68,0x4C,0x4C,0xFC,0x10,0x00,0x20,0x06,0xC2,0x00,0x04,0x06,0x0C,0x00}},
        {0xA0,4,{0x00,0x92,0x00,0x00}},
//Blank 17
        {0x41,2,{0x5A,0x10}},
        {0x80,16,{0x00,0x00,0x03,0xE7,0x1F,0x17,0x10,0x48,0x80,0xAA,0xD0,0x18,0x30,0x88,0x41,0x8A}},
        {0x90,15,{0x39,0x28,0xA9,0xC5,0x9A,0x7B,0xF0,0x07,0x7E,0xE0,0x07,0x7E,0x20,0x10,0x00}},
//Blank 18
        {0x41,2,{0x5A,0x11}},
        {0x80,16,{0x49,0x77,0x03,0x40,0xCA,0xF3,0xFF,0x83,0x30,0x08,0xC4,0x06,0xA1,0xD8,0x24,0x18}},
        {0x90,16,{0x30,0xC6,0x66,0xC1,0x80,0x31,0x15,0xCB,0xE5,0xD2,0x68,0x6C,0x36,0x1D,0x04,0xC8}},
        {0xA0,16,{0xB0,0xD9,0x88,0x60,0xB0,0x81,0x40,0x1A,0x1B,0x48,0x63,0x03,0xB9,0x00,0x1C,0x80}},
        {0xB0,16,{0x50,0x30,0x00,0xE0,0xE1,0x01,0x00,0x28,0x0E,0x06,0x43,0x55,0x55,0x55,0x55,0x55}},
		{0xC0,16,{0x95,0x88,0x88,0x88,0x88,0x88,0xC8,0x08,0x86,0xC6,0xE3,0x81,0x00,0x20,0x00,0x21}},
		{0xD0,16,{0x42,0x88,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x31,0x04,0x41,0x06,0x00,0x00,0x00}},
		{0xE0,16,{0x00,0x92,0x04,0x00,0x92,0x04,0x00,0x00,0x00,0x00,0x92,0x04,0x00,0x85,0x11,0x0C}},
		{0xF0,15,{0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x5E,0x4A,0x01,0x78,0x00,0x08,0x00,0x00}},
        //{0xC0,4,{0x05,0xFB,0x00,0x01}},

        {0x41,2,{0x5A,0x12}},
        {0x80,16,{0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x00,0x00,0x00,0x00,0x02,0x03,0x01,0x41,0x37}},
        {0x90,16,{0xF1,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2D,0x23,0x05}},
        {0xA0,7,{0xFB,0x08,0x2D,0x23,0x05,0xFB,0x0C}},

        {0x41,2,{0x5A,0x13}},
        {0x80,16,{0xFD,0x0F,0x00,0x0C,0x00,0x00,0x00,0x00,0x01,0x08,0x01,0x1C,0x44,0x0C,0xCE,0xE7}},
        {0x90,14,{0x62,0x0E,0x24,0x98,0xAC,0x21,0xB3,0x88,0xD0,0xFF,0xFF,0xFF,0x07,0x24}},
       

        {0x41,2,{0x5A,0x14}},
        {0x80,16,{0x01,0x02,0xC9,0x38,0xE1,0xEF,0xF7,0xFB,0xFD,0x7E,0x01,0x00,0x00,0x90,0xC5,0x88}},
        {0x90,16,{0xE8,0x3D,0x20,0x3E,0x44,0xEF,0x01,0xB1,0x21,0x7A,0x0F,0x88,0x0B,0xD1,0x7B,0x00}},
        {0xA0,16,{0x00,0x00,0x00,0x00,0x4E,0x00,0xDF,0x0F,0x00,0x20,0x03,0x00,0x00,0x00,0x00,0x00}},
        {0xB0,16,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0xB2,0x21,0x2B,0x00,0x40,0xA1}},
        {0xC0,16,{0x50,0x78,0x07,0xE4,0xF7,0x8C,0x51,0x1C,0x6F,0x80,0xFC,0x9E,0x31,0x8A,0xE3,0x05}},
        {0xD0,16,{0x90,0xDF,0x33,0x46,0x71,0xBC,0x02,0xF2,0x7B,0xC6,0x28,0x8E,0x77,0x41,0x7E,0xCF}},
        {0xE0,16,{0x18,0xC5,0xF1,0x26,0xC8,0xEF,0x19,0xA3,0x38,0xDE,0x03,0xF9,0x3D,0x63,0x14,0xC7}},
        {0xF0,16,{0x5B,0x20,0xBF,0x67,0x8C,0xE2,0x18,0x01,0xBF,0xDF,0x08,0x00,0x00,0x00,0x00,0x00}},
//Blank 22
        {0x41,2,{0x5A,0x15}},
    {0x80,16,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x52,0xD9,0xE0,0xF7}},
		{0x90,16,{0xA3,0x00,0x26,0x4B,0xC5,0xA8,0xC5,0x07,0xC9,0x90,0x5F,0x31,0x6A,0xF1,0x41,0x0A}},
		{0xA0,16,{0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90}},
		{0xB0,16,{0x5D,0xA1,0x28,0x14,0x00,0x00,0x00,0x00,0x13,0x00,0xF0,0x00,0x94,0x56,0x23,0x4D}},
		{0xC0,16,{0xC9,0x02,0x41,0xC1,0x50,0x9C,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0x55,0xCC}},
		{0xD0,16,{0xA4,0x20,0x13,0x64,0x10,0x02,0x68,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0x56,0x23}},
		{0xE0,16,{0x4D,0x88,0x02,0x41,0x80,0x40,0x98,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0x55}},
		{0xF0,16,{0xCC,0xB4,0x24,0x50,0x75,0x14,0x43,0x68,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0x5B,0xC0}},
        //{0x90,10,{0x00,0x00,0x00,0x00,0x80,0x42,0x2B,0x01,0x00,0x00}},
//Blank 24
        {0x41,2,{0x5A,0x16}},
        {0x80,16,{0xC3,0x43,0x41,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
        
        {0x90,6,{0x00,0x00,0x00,0x00,0xF0,0x20}},

        {0x41,2,{0x5A,0x18}},
        {0x80,16,{0xEF,0xBD,0xF7,0xDE,0x7B,0xEF,0xBD,0x07,0x08,0x08,0x0A,0x0C,0x0C,0x0C,0x0C,0x0C}},
        {0x90,16,{0x0C,0x0C,0x0C,0x5C,0x09,0xA8,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x5A}},
	{0xA0,16,{0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x09,0x04,0xFF,0x00,0x80}},
        {0xB0,15,{0x80,0x00,0x04,0x20,0x00,0x01,0x08,0x40,0x00,0x02,0x10,0x80,0x00,0x04,0x00}},

        {0x41,2,{0x5A,0x19}},
        {0x80,16,{0xC0,0xAF,0xA3,0x9B,0x92,0x8D,0x8A,0x86,0x84,0x83,0x82,0x81,0x00,0x50,0xF6,0xCF}},
        {0x90,16,{0xFC,0x2F,0xF3,0xEF,0xCF,0xBF,0x0F,0xFF,0xAF,0xB5,0x71,0x0E,0x6C,0x4A,0x69,0x08}},
        {0xA0,4,{0x05,0x05,0x02,0x00}},
    

        {0x41,2,{0x5A,0x1A}},
    {0x80,16,{0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38,0x00,0x40}},
    {0x90,16,{0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00,0xA0,0xA8}},
    {0xA0,16,{0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC,0xFE,0xFF}},
    {0xB0,16,{0x00,0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38,0x00}},
    {0xC0,16,{0x40,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00,0xA0}},
    {0xD0,16,{0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC,0xFE}},
    {0xE0,16,{0xFF,0x00,0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38}},
    {0xF0,16,{0x00,0x40,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00}},
 
        {0x41,2,{0x5A,0x1B}},
        {0x80,16,{0xA0,0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC}},
        {0x90,4,{0xFE,0xFF,0x00,0x00}},
       

        {0x41,2,{0x5A,0x20}},
        {0x80,7,{0x84,0x00,0x00,0x00,0x00,0x00,0x00}},
//Blank 34
        {0x41,2,{0x5A,0x22}},
        {0x80,13,{0x2D,0xD3,0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x9F,0x00}},
//Blank 36
        {0x41,2,{0x5A,0x23}},
        {0x80,16,{0x01,0x05,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
        {0x90,12, {0xFF,0x0F,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xFF,0x07,0x35}},

        {0x41,2,{0x5A,0x24}},
        {0x80,16,{0x00,0x03,0x00,0xFF,0xFF,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD4,0xBD}},
        {0x90,16,{0x5A,0x5A,0x5A,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},



//----------------------LCD initial code End----------------------//

//SPI FINISH
        {0x42,1,{0x24}},

        {0x90,1,{0x00}},
		
		{0x41,1,{0x5a,0x2F}},
		{0x19,1,{0x00}},
		{0x4C,1,{0x03}},

{0x11,1,{0x00}},
{REGFLAG_DELAY,120, {}},
{0x29,1,{0x00}},
  {0x51,2,{0xff,0x0f}},
		
		{0x53,1,{0x24}},
		{0x55,1,{0x00}},
{REGFLAG_DELAY, 20, {}},
//-------------  Display Initial Setting end -------------------------
	{REGFLAG_END_OF_TABLE, 0x00, {}}    
};

static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
{
    unsigned int i;

    for (i = 0; i < count; i++)
    {
        unsigned cmd;
        cmd = table[i].cmd;

        switch (cmd)
        {
        case REGFLAG_DELAY:
            if (table[i].count <= 10)
                MDELAY(table[i].count);
            else
                MDELAY(table[i].count);
            break;

        case REGFLAG_END_OF_TABLE:
            break;

        default:
            dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
        }
    }
}

/* --------------------------------------------------------------------------- */
/* LCM Driver Implementations */
/* --------------------------------------------------------------------------- */

static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
{
	memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
}

static void lcm_get_params(LCM_PARAMS *params)
{
	memset(params, 0, sizeof(LCM_PARAMS));

	params->type                         = LCM_TYPE_DSI;
	params->width                        = FRAME_WIDTH;
	params->height                       = FRAME_HEIGHT;

	#ifndef BUILD_LK
	params->physical_width               = 68;
	params->physical_height              = 151;
	params->physical_width_um            = 67930;
	params->physical_height_um           = 150960;
	params->density                      = 320;
	#endif

	// enable tearing-free
	params->dbi.te_mode                  = LCM_DBI_TE_MODE_VSYNC_ONLY;
	params->dbi.te_edge_polarity         = LCM_POLARITY_RISING;

	#if (LCM_DSI_CMD_MODE)
	params->dsi.mode                     = CMD_MODE;
	params->dsi.switch_mode              = SYNC_PULSE_VDO_MODE;
	#else
	params->dsi.mode                     = SYNC_PULSE_VDO_MODE;//SYNC_EVENT_VDO_MODE;//BURST_VDO_MODE;////
	#endif

	// DSI
	/* Command mode setting */
	//1 Three lane or Four lane
	params->dsi.LANE_NUM                 = LCM_FOUR_LANE;
	//The following defined the fomat for data coming from LCD engine.
	params->dsi.data_format.color_order  = LCM_COLOR_ORDER_RGB;
	params->dsi.data_format.trans_seq    = LCM_DSI_TRANS_SEQ_MSB_FIRST;
	params->dsi.data_format.padding      = LCM_DSI_PADDING_ON_LSB;
	params->dsi.data_format.format       = LCM_DSI_FORMAT_RGB888;

	params->dsi.PS                       = LCM_PACKED_PS_24BIT_RGB888;

	#if (LCM_DSI_CMD_MODE)
	params->dsi.intermediat_buffer_num   = 0;//because DSI/DPI HW design change, this parameters should be 0 when video mode in MT658X; or memory leakage
	params->dsi.word_count               = FRAME_WIDTH * 3; //DSI CMD mode need set these two bellow params, different to 6577
	#else
	params->dsi.intermediat_buffer_num   = 2;	//because DSI/DPI HW design change, this parameters should be 0 when video mode in MT658X; or memory leakage
	#endif

	// Video mode setting
	params->dsi.packet_size              = 256;
params->dsi.vertical_sync_active     = 8;
	params->dsi.vertical_backporch       = 45;
	params->dsi.vertical_frontporch      = 75;
	params->dsi.vertical_active_line     = FRAME_HEIGHT;

	params->dsi.horizontal_sync_active   = 16;
	params->dsi.horizontal_backporch     = 45;//36
	params->dsi.horizontal_frontporch    = 48;//78
	
	params->dsi.horizontal_active_pixel  = FRAME_WIDTH;
	/* params->dsi.ssc_disable = 1; */

	params->dsi.PLL_CLOCK                = 270;
	params->dsi.ssc_disable                         = 0;
	params->dsi.ssc_range                           = 4;
	params->dsi.esd_check_enable = 1;
	params->dsi.customization_esd_check_enable = 1;
	params->dsi.lcm_esd_check_table[0].cmd          = 0x0a;
	params->dsi.lcm_esd_check_table[0].count        = 1;
	params->dsi.lcm_esd_check_table[0].para_list[0] = 0x9c;
}


#define AUXADC_LCM_VOLTAGE_CHANNEL (2)
#define MIN_VOLTAGE (900000)
#define MAX_VOLTAGE (1100000)
extern int IMM_GetOneChannelValue_Cali(int Channel, int *voltage);
static unsigned int lcm_compare_id(void)
{
    int res = 0;
    int lcm_vol = 0;
#ifdef AUXADC_LCM_VOLTAGE_CHANNEL
    res = IMM_GetOneChannelValue_Cali(AUXADC_LCM_VOLTAGE_CHANNEL,&lcm_vol);
    if(res < 0)
    {
#ifdef BUILD_LK
        dprintf(0,"lixf lcd [adc_uboot]: get data error\n");
#endif
        return 0;
    }
#endif
#ifdef BUILD_LK
    dprintf(0,"lsw lk: lcm_vol= %d , file : %s, line : %d\n",lcm_vol, __FILE__, __LINE__);
#else
    printk("lsw kernel: lcm_vol= %d , file : %s, line : %d\n",lcm_vol, __FILE__, __LINE__);
#endif
    if (lcm_vol >= MIN_VOLTAGE && lcm_vol <= MAX_VOLTAGE)
    {
        return 1;
    }


    return 0;
}

static void lcm_init(void)
{
//prize-add-pengzhipeng-20191128-start
	int ret = 0;

	/*config rt5081 register 0xB2[7:6]=0x3, that is set db_delay=4ms.*/
	ret = PMU_REG_MASK(0xB2, (0x3 << 6), (0x3 << 6));

	/* set AVDD 5.4v, (4v+28*0.05v) */
	/*ret = RT5081_write_byte(0xB3, (1 << 6) | 28);*/
	ret = PMU_REG_MASK(0xB3, 28, (0x3F << 0));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB3);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB3);

	/* set AVEE */
	/*ret = RT5081_write_byte(0xB4, (1 << 6) | 28);*/
	ret = PMU_REG_MASK(0xB4, 28, (0x3F << 0));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB4);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB4);

	/* enable AVDD & AVEE */
	/* 0x12--default value; bit3--Vneg; bit6--Vpos; */
	/*ret = RT5081_write_byte(0xB1, 0x12 | (1<<3) | (1<<6));*/
	ret = PMU_REG_MASK(0xB1, (1<<3) | (1<<6), (1<<3) | (1<<6));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB1);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB1);
//prize-add-pengzhipeng-20191128-end
	MDELAY(10);
    MDELAY(5);
    SET_RESET_PIN(1);
    MDELAY(5);
    SET_RESET_PIN(0);
    MDELAY(5);
    SET_RESET_PIN(1);
    MDELAY(10);
    
    push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
}

static void lcm_suspend(void)
{
//prize-add-pengzhipeng-20191128-start
	int ret = 0;
//prize-add-pengzhipeng-20191128-end
    push_table(lcm_suspend_setting, sizeof(lcm_suspend_setting) / sizeof(struct LCM_setting_table), 1);

    SET_RESET_PIN(1);
    MDELAY(5);
//prize-add-pengzhipeng-20191128-start
	ret = PMU_REG_MASK(0xB1, (0<<3) | (0<<6), (1<<3) | (1<<6));
	if (ret < 0)
		dprintf("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB1);
	else
		dprintf("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB1);

	MDELAY(5);
//prize-add-pengzhipeng-20191128-end
}

static void lcm_resume(void)
{
    lcm_init();
}

LCM_DRIVER ft8006s_ab_hdp_dsi_vdo_boe_drip_incell_lcm_drv =
{
    .name			= "ft8006s_ab_hdp_dsi_vdo_boe_drip_incell",
#if defined(CONFIG_PRIZE_HARDWARE_INFO) && !defined (BUILD_LK)
	.lcm_info = {
		.chip	= "ft8006s_ab",
		.vendor	= "focaltech",
		.id		= "0x82",
		.more	= "720*1600",
	},
#endif
    .set_util_funcs = lcm_set_util_funcs,
    .get_params     = lcm_get_params,
    .init           = lcm_init,
    .suspend        = lcm_suspend,
    .resume         = lcm_resume,
    .compare_id     = lcm_compare_id,
};
